<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <base href="<?= base_url(1); ?>" />
        <link type="text/css" href="css/main.css?v=<?= $config['version'] ?>" rel="stylesheet" />
    </head>
    <body>
        <?php include(VIEWPATH . 'common/main_header.php'); ?>
        <div class="datalist"><table id="flexigrid" style="display:none"></table></div>
        <script type="text/javascript">
            $(function() {
                $("#flexigrid").flexigrid($.extend(SG.flexOptions, {
                    url: '<?= site_url('area/area/flexigrid') ?>',
                    colModel: [
                        {display: 'ID', name: 'SvrID', width: '120', iskey: true},
//                        {display: '<?= translate('AREA_FATHER_ID') ?>', name: 'father_id', width: '100', process: formatSearch},
                        {display: '<?= translate('AREA_NAME') ?>', name: 'SvrName', width: '120', sortable: false},
//                        {display: 'URL', name: 'url', width: '300'},
                        {display: '<?= translate('AREA_HOST') ?>', name: 'SvrOutAddr', width: '300'},
//                        {display: '<?= translate('AREA_PLAYERS') ?>', name: 'players', width: '80', process: formatSearch},
//                        {display: '<?= translate('AREA_WEIGH') ?>', name: 'weigh', width: '60', process: formatSearch, hide: true},
//                        {display: '<?= translate('AREA_ODDS') ?>', name: 'odds', width: '60', process: formatSearch},
                        {display: '<?= translate('AREA_OPENTIME') ?>', name: 'SvrOpenTime', width: '120'},
            //            {display: '<?= translate('AREA_LAST_OPENTIME') ?>', name: 'lastopentime', width: '120'},
                        {display: '<?= translate('STATUS') ?>', name: 'SvrState', width: '80', process: formatAreaState},
                      //  {display: '<?= translate('FLAG') ?>', name: 'flag', width: '80', process: formatAreaFlag},
//                        {display: '<?= translate('SHORTCUT') ?>', name: 'SvrID', width: '80', process: formatUrl},
                        {display: '<?= translate('MANAGE') ?>', name: 'SvrID', width: '200', sortable: false, process: formatOp},
                    ],
                    buttons: [
                        {name: 'add', displayname: "<?= translate('ADD') ?>", title: "<?= translate('ADD') ?>", bclass: 'add', onpress: multi},
                        {name: 'delete', displayname: "<?= translate('DEL') ?>", title: "<?= translate('DEL') ?>", bclass: 'delete', onpress: multi},
                        { name: 'reject', displayname: "<?=translate('CLOSE')?>", bclass: 'reject', onpress: multi },
                        { name: 'accept', displayname: "<?=translate('OPEN')?>", bclass: 'accept', onpress: multi },
                        { name: 'new', displayname: "<?=translate('AREA_STATUS_NEW')?>", bclass: 'alert', onpress: multi },
                        {name: 'export', displayname: "<?= translate('EXPORT') ?>", bclass: 'export', onpress: multi},
                        {separator: true},
                    ],
                    searchitems: true,
                    sortname: "weigh",
                    sortorder: "desc",
                }));
                SG.admin = $.extend(SG.admin, {
                    add_url: '<?= site_url("area/area/add/") ?>',
                    edit_url: '<?= site_url("area/area/edit/") ?>',
                    replay_url: '<?= site_url("area/area/maintain/") ?>',
                    del_url: '<?= site_url("area/area/del/") ?>',
                    multi_url: '<?= site_url("area/area/multi/") ?>',
                    table: '{pre}areasample'
                });

                function formatUrl(value, id, cell) {
                    if (cell[0] == cell[1]) {
                        return "<a href='" + value + "' target='_blank'><?= translate('MANAGE') ?></a>";
                    } else {
                        return "<?= translate('NONE') ?>";
                    }
                }

                function formatAreaState(value, id, cell, field) {
                    var typearr = <?= json_encode($statelist); ?>;
                    var arr = [];
                    
                    $.each(typearr, function(i, j) {
                        var color = i == 'hide' ? 'gray' : (i == 'new' ? 'red' : (i == 'prepare' ? 'green' : (i == 'close' ? 'gray' : '')))
                        arr.push({color: color, text: j, value: i});
                    });
                    return filterGeneral(arr, value, field);
                }
                
                function formatAreaFlag(value, id, cell, field) {
                    var typearr = <?= json_encode($flaglist); ?>;
                    var arr = [];
                    
                    $.each(typearr, function(i, j) {
                        var color = i == 'hide' ? 'gray' : (i == 'new' ? 'red' : (i == 'prepare' ? 'green' : (i == 'close' ? 'gray' : '')))
                        arr.push({color: color, text: j, value: i});
                    });
                    return filterGeneral(arr, value, field);
                }
            });
        </script>
    </body>
</html>